Skip to content

Conversation

@uyeon0
Copy link
Collaborator

@uyeon0 uyeon0 commented Jan 20, 2026

User description

오늘도 멋져요 👍✨


PR Type

Enhancement


Description

  • 프로그래머스 12928번 약수의 합 문제 해결

  • 효율적인 약수 찾기 알고리즘 구현

  • 제곱근까지만 탐색하여 모든 약수 계산


@uyeon0 uyeon0 added the programmers Programmers 문제 풀이 label Jan 20, 2026
@github-actions
Copy link

PR Reviewer Guide 🔍

🧪 No relevant tests
⚡ Recommended focus areas for review

Performance Optimization

현재 구현된 약수 찾기 알고리즘은 시간 복잡도 O(√n)으로 효율적입니다.
추가로 고려할 점은 큰 정수에 대한 오버플로우 방지와 정수 나눗셈의 정확성입니다.

function getDivisors(n) {
  const divisors = [];

  for (let i = 1; i * i <= n; i++) {
    if (n % i === 0) {
      divisors.push(i);
      if (n / i !== i) {
        divisors.push(n / i);
      }
    }
  }

  return divisors;
}
Edge Case

0과 음수 입력에 대한 예외 처리가 필요합니다.
현재 구현은 이러한 입력에 대해 어떻게 동작할지 명확하지 않습니다.

function solution(n) {
  return getDivisors(n).reduce((acc, cur) => acc + cur, 0);
}

@github-actions
Copy link

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
General
약수 합계 직접 계산

현재 구현은 잘 되어 있지만, 성능과 가독성을 개선할 수 있습니다. 약수의 합을 직접 계산하면 불필요한 배열 생성을 피할 수 있습니다.

Programmers/Level1/12928_약수의_합.js [13-30]

-function getDivisors(n) {
-  const divisors = [];
-
+function solution(n) {
+  let sum = 0;
   for (let i = 1; i * i <= n; i++) {
     if (n % i === 0) {
-      divisors.push(i);
+      sum += i;
       if (n / i !== i) {
-        divisors.push(n / i);
+        sum += n / i;
       }
     }
   }
-
-  return divisors;
+  return sum;
 }
 
-function solution(n) {
-  return getDivisors(n).reduce((acc, cur) => acc + cur, 0);
-}
-
Suggestion importance[1-10]: 8

__

Why: The suggestion removes the unnecessary getDivisors() function and directly calculates the sum of divisors, improving both performance and memory efficiency by avoiding array creation.

Medium

@yoouyeon yoouyeon added the ready-to-merge pr을 머지해주세요 label Jan 21, 2026
@uyeon0 uyeon0 merged commit 23b27dc into main Jan 21, 2026
11 of 12 checks passed
@yoouyeon yoouyeon self-assigned this Jan 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

programmers Programmers 문제 풀이 ready-to-merge pr을 머지해주세요

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants